<?php
defined('SYSPATH') or die('No direct script access.') ;
/**
 * @category 360hqb
 * @package  cli
 * @author   clooney<wjj706@126.com>
 */
class Cli_Inserttrade extends CLI
{
	public function main()
	{    
	    $select = DB::select('o.is_anonymity', 'm.member_id','m.nickname', 'g.goods_id', 'g.goods_title', 'og.prop_str', 'og.original_price', 'og.price','og.quantity', 'o.created')
			->from(array('order_goods', 'og'))
			->join(array('orders', 'o'), 'inner')
			->on('o.order_id', '=', 'og.order_id')
			->join(array('goods', 'g'), 'inner')
			->on('g.goods_id', '=', 'og.goods_id')
			->join(array('members', 'm'), 'inner')
			->on('m.member_id', '=', 'o.member_id')
			->where('og.status', '<>', 'TRADE_CLOSED')
			->where('o.order_status', 'in', array('WAIT_BUYER_CONFIRM_GOODS','TRADE_FINISHED','WAIT_SELLER_SEND_GOODS'));

		/*$select = DB::select(DB::expr('distinct(goods_id)'))
			->from('goods_props')
			->where('props', 'REGEXP', '^[0-9]+$')
			->or_where('props', 'REGEXP', '[0-9]+;');*/

		$iterator = new Db_Iterator($select, 'default', 10);

		while ($iterator->valid())
		{
			foreach ($iterator->current() as $g)
			{
				if ( ! empty($g))
				{  
					DB::insert('order_trades', array_keys($g))->values(array_values($g))->execute();
					CLI::output("商品ID".$g['goods_id']."更新成功...\n");
				}
			}
			$iterator->next();
		}
		CLI::output("更新完毕...");
	}
}